package com.zhanggm.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zhanggm.springcloud.pojo.Order;
import org.aspectj.bridge.MessageWriter;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Random;

@Service
public class OrderService {
    /**
     * HystrixCommand注解，对方法本身做了服务降级
     * @param id
     * @return
     */
    @HystrixCommand(fallbackMethod = "getByIdFallbak")
    public Order getById(Integer id){
        Order order = new Order();
        order.setId(id);
        order.setOrderNo("orderno"+id);
        order.setCreateTime(new Date());
        Random random = new Random();
        order.setUserId(random.nextInt());
        return order;
    }

    public Order getByIdFallbak(Integer id){
        return new Order();
    }
}
